<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
class RealSalary extends Common{
	

    //基础信息类页面渲染
    public function index(){
        return $this->fetch();
    }
    //编辑页面
    public function edit(){
        $id = request()->param('id');
        $info = Db('user')
        ->alias("user")
        ->join('realsalary_info', 'user.id = realsalary_info.user_id')
        ->where('user.id','=',$id)
        ->find();
        $this->assign('info', $info);
        return $this->fetch();
    }

    public function getrealsalary(){
        $page = request()->param('page');
        $limit = request()->param('limit');
        $type = request()->param('type');
        $start = ($page-1) * $limit;
        $modules = input("modules");
        $value =input("value");


        if($value && $modules){
            $info = Db('user')
            ->alias("user")
            ->join('realsalary_info', 'user.id = realsalary_info.user_id')
            ->where($modules,'LIKE','%'.$value .'%')
            ->where('realsalary_info.isdelete',0)
            ->limit($start,$limit)
            ->select();
            
            $count =  Db('user')
            ->limit($start,$limit)
            ->count();
        }else{
            $info = Db('user')
            ->alias("user")
            ->join('realsalary_info', 'user.id = realsalary_info.user_id')
            ->where('realsalary_info.isdelete',0)
            ->limit($start,$limit)
            ->select();
            
            $count =  Db('user')
            ->limit($start,$limit)
            ->count();
        }

        

        $msg = [
            'code' => 0,
            'msg' => '查询成功',
            'data' => $info,
            'count' => $count
        ];
        
        echo json_encode($msg);
    }
	
    //用户页面编辑信息处理
    public function editPost(){
        $id = request()->param('id');
        $status=Db('user')
        ->alias("user")
        ->join('realsalary_info', 'user.id = realsalary_info.user_id')
        ->where('user.id','=',$id)
        ->update([
            "realsalary_info.job_salary" =>request()->param("job_salary"),
            "realsalary_info.job_level_salary" =>request()->param("job_level_salary"),
            "realsalary_info.retention_benefit_subsidy" =>request()->param("retention_benefit_subsidy"),
            "realsalary_info.job_reward_performance_salary" =>request()->param("job_reward_performance_salary"),
            "realsalary_info.basic_performance_award" =>request()->param("basic_performance_award"),
            "realsalary_info.special_post_allowance" =>request()->param("special_post_allowance"),
            "realsalary_info.property_subsidy" =>request()->param("property_subsidy"),
            "realsalary_info.civilization_award" =>request()->param("civilization_award"),
            "realsalary_info.one_child_fee" =>request()->param("one_child_fee"),
            "realsalary_info.ethnic_minorities_subsidy" =>request()->param("ethnic_minorities_subsidy"),
            "realsalary_info.public_sanitation_fee" =>request()->param("public_sanitation_fee"),
            "realsalary_info.doctor_subsidy" =>request()->param("doctor_subsidy"),
            "realsalary_info.professor_subsidy" =>request()->param("professor_subsidy"),
            "realsalary_info.rental_subsidy" =>request()->param("rental_subsidy"),
            "realsalary_info.car_supplement" =>request()->param("car_supplement"),
            "realsalary_info.supplementary_salary" =>request()->param("supplementary_salary"),
            "realsalary_info.housing_provident_fund" =>request()->param("housing_provident_fund"),
            "realsalary_info.medical_insurance_fund" =>request()->param("medical_insurance_fund"),
            "realsalary_info.endowment_insurance_individual_enterprise" =>request()->param("endowment_insurance_individual_enterprise"),
            "realsalary_info.endowment_insurance_individual" =>request()->param("endowment_insurance_individual"),
            "realsalary_info.occupational_annuity_individual" =>request()->param("occupational_annuity_individual"),
            "realsalary_info.deduction_of_individual_income_tax" =>request()->param("deduction_of_individual_income_tax"),
            "realsalary_info.deduction_of_rent" =>request()->param("deduction_of_rent"),
            "realsalary_info.withholding_property" =>request()->param("withholding_property"),
            "realsalary_info.deduction_of_hydropower" =>request()->param("deduction_of_hydropower"),
            "realsalary_info.deduction_of_wages" =>request()->param("deduction_of_wages"),
            "realsalary_info.heating_fee" =>request()->param("heating_fee"),
            "realsalary_info.target_assessment_award" =>request()->param("target_assessment_award"),
            "realsalary_info.national_civilized_city_award" =>request()->param("national_civilized_city_award"),
            "realsalary_info.merit_pay" =>request()->param("merit_pay")
        ]);
        if($status){
            $this->success('更新成功');
        }else{
            $this->error('更新失败');
        }
    }
}